'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 副本通关条件判断
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');
var ccBeAttackNumLess = require('./copyCondition/ccBeAttackNumLess');
var ccCallSkillNumLess = require('./copyCondition/ccCallSkillNumLess');
var ccCallSoldierNotLess = require('./copyCondition/ccCallSoldierNotLess');
var ccCallSoldierNotMore = require('./copyCondition/ccCallSoldierNotMore');
var ccDestroyAllBuild = require('./copyCondition/ccDestroyAllBuild');
var ccDestroyNexus = require('./copyCondition/ccDestroyNexus');
var ccDontTakeSoldier = require('./copyCondition/ccDontTakeSoldier');
var ccHeroHpNotLess = require('./copyCondition/ccHeroHpNotLess');
var ccKillSoldierNotLess = require('./copyCondition/ccKillSoldierNotLess');
var ccKillSoldierNotMore = require('./copyCondition/ccKillSoldierNotMore');
var ccPassTimeNotLess = require('./copyCondition/ccPassTimeNotLess');
var ccSoldierLostCommandLess = require('./copyCondition/ccSoldierLostCommandLess');
var ccSoldierLostNumLess = require('./copyCondition/ccSoldierLostNumLess');
var ccTakeSoldier = require('./copyCondition/ccTakeSoldier');
var copyConditionType = require('../consts/copyConditionType');
var ccPassTimeBiggerThan = require('./copyCondition/ccPassTimeBiggerThan');

var copy_condition_instances = {};

// 1.摧毁城堡
copy_condition_instances[copyConditionType.DESTROY_NEXUS] = function () {
    return ccDestroyNexus;
};

// 2.过关剩余时间不少于$1秒
copy_condition_instances[copyConditionType.PASS_TIME_NOT_LESS] = function () {
    return ccPassTimeNotLess;
};

// 3.英雄剩余血量不曾低于$1%
copy_condition_instances[copyConditionType.HERO_HP_NOT_LESS] = function () {
    return ccHeroHpNotLess;
};

// 4.必须带$1参战
copy_condition_instances[copyConditionType.TAKE_SOLDIER] = function () {
    return ccTakeSoldier;
};

// 5.不带$1参战
copy_condition_instances[copyConditionType.DONT_TAKE_SOLDIER] = function () {
    return ccDontTakeSoldier;
};

// 6.士兵损失小于$1统帅
copy_condition_instances[copyConditionType.SOLDIER_LOST_COMMAND_LESS] = function () {
    return ccSoldierLostCommandLess;
};

// 7.士兵损失小于$1个
copy_condition_instances[copyConditionType.SOLDIER_LOST_NUM_LESS] = function () {
    return ccSoldierLostNumLess;
};

// 8.召唤$1不少于$2个
copy_condition_instances[copyConditionType.CALL_SOLDIER_NOT_LESS] = function () {
    return ccCallSoldierNotLess;
};

// 9.召唤$1不大于$2个
copy_condition_instances[copyConditionType.CALL_SOLDIER_NOT_MORE] = function () {
    return ccCallSoldierNotMore;
};

// 10.击杀$1不少于$2个
copy_condition_instances[copyConditionType.KILL_SOLDIER_NOT_LESS] = function () {
    return ccKillSoldierNotLess;
};

// 11.击杀$1不大于$2个
copy_condition_instances[copyConditionType.KILL_SOLDIER_NOT_MORE] = function () {
    return ccKillSoldierNotMore;
};

// 12.英雄技能释放少于$1次
copy_condition_instances[copyConditionType.CALL_SKILL_NUM_LESS] = function () {
    return ccCallSkillNumLess;
};

// 13.英雄受击次数少于$1次
copy_condition_instances[copyConditionType.BE_ATTACK_NUM_LESS] = function () {
    return ccBeAttackNumLess;
};

// 14.摧毁所有建筑
copy_condition_instances[copyConditionType.DESTROY_ALL_BUILD] = function () {
    return ccDestroyAllBuild;
};

// 16.过关剩余时间不少于$1秒
copy_condition_instances[copyConditionType.PASS_TIME_BIGGER_THAN] = function () {
    return ccPassTimeNotLess;
};

/**
 * 判断条件是否满足
 * @param  {[type]}  build_list [description]
 * @param  {[type]}  road_list  [description]
 */
exports.getProgress = function (condition, record, damage_build_list, data) {
    var instance = _getInstance(condition.type);
    return instance.getProgress(condition, record, damage_build_list, data);
};

var _getInstance = function (condition_type) {
    var instance = copy_condition_instances[condition_type];
    if (!!instance) {
        return instance();
    } else {
        throw new Error('copy condition type can not found:' + condition_type);
    }
};
